package org.wyf.EveryPoint.crowd.service.impl;

import org.wyf.EveryPoint.common.entity.QueryRequest;
import org.wyf.EveryPoint.crowd.entity.Team;
import org.wyf.EveryPoint.crowd.mapper.TeamMapper;
import org.wyf.EveryPoint.crowd.service.ITeamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 项目小组 Service实现
 *
 * @author wyf
 * @date 2021-04-09 16:44:58
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements ITeamService {

    private final TeamMapper teamMapper;

    @Override
    public IPage<Team> findTeams(QueryRequest request, Team team) {
        LambdaQueryWrapper<Team> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<Team> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<Team> findTeams(Team team) {
	    LambdaQueryWrapper<Team> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createTeam(Team team) {
        this.save(team);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateTeam(Team team) {
        this.saveOrUpdate(team);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteTeam(Team team) {
        LambdaQueryWrapper<Team> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    public List<Team> findProjectTeams(Long userId, Long projectId) {
        return this.teamMapper.findProjectTeams(userId,projectId);
    }

    @Override
    public List<Long> findProjectTeamsByProjectId(Long projectId) {
        return this.teamMapper.findProjectTeamsByProjectId(projectId);
    }
}
